#!/bin/bash
# run with ./parameter.sh gonwan apple banana peach pineapple

# $0, basename
echo The command entered is: $0
name=`basename $0`
echo The basename of command entered is: $name

# testing $1
# If your script needs more than nine command line parameters, you can continue,
# but the variable names change slightly. After the ninth variable, you must use
# braces around the variable number, such as ${10}.
if [ -n "$1" ]; then
    echo Hello $1, glad to meet you.
else
    echo "Sorry, you did not identify yourself."
fi

# $# is count
echo There were $# parameters supplied
echo The last parameter was ${!#}

# $* treats all as a single parameter
count=1
for param in "$*"; do
    echo "\$* Parameter #$count = $param"
    count=$[ $count + 1 ]
done

# $@ treats each parameter separately
count=1
for param in "$@"; do
    echo "\$@ Parameter #$count = $param"
    count=$[ $count + 1 ]
done

# shift 2
echo "The original parameters: $*"
shift 2
echo "Here's the new first parameter: $1"
# shift 1
count=1
while [ -n "$1" ]; do
    echo "Parameter #$count = $1"
    count=$[ $count + 1 ]
    shift
done

